package com.dodock.survey.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.dodock.survey.Brave;
import com.dodock.survey.R;

public class HomeActivity extends Activity implements OnClickListener{
	
	int btnlist[] = { R.id.newFormBtn , R.id.openPreviousBtn , R.id.settingsBtn };
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.home_layout);
		
		for(int i = 0; i < btnlist.length ; i++){
			Button button = (Button) findViewById(btnlist[i]);
			button.setOnClickListener(this);
		}
	}

	@Override
	public void onClick(View view) {
		// TODO Auto-generated method stub
		
		switch (view.getId()) {
		
		case R.id.openPreviousBtn:		
			Intent listActivity = new Intent( this, OpenList.class);
			startActivity(listActivity);
			break;
			
		case R.id.newFormBtn:
			Intent infoActivity = new Intent( this, SectionActivity.class);
			infoActivity.putExtra("newForm", true);
			infoActivity.putExtra("itemNo", 0);
			startActivity(infoActivity);
			break;
			
		case R.id.settingsBtn:
			break;
		default:
			break;
		}
	}
	
	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		super.onBackPressed();
		Brave.getDatabaseManager().closeDB();
	}
}
